package com.university.evaluation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.university.evaluation.entity.EvaluationRule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 考评规则Mapper
 */
@Mapper
public interface EvaluationRuleMapper extends BaseMapper<EvaluationRule> {

    /**
     * 根据学院ID和学期查询规则
     */
    @Select("SELECT * FROM t_evaluation_rule WHERE college_id = #{collegeId} AND semester = #{semester}")
    EvaluationRule findByCollegeAndSemester(@Param("collegeId") String collegeId, @Param("semester") String semester);

    /**
     * 根据学院ID、学期和状态查询规则
     */
    @Select("SELECT * FROM t_evaluation_rule WHERE college_id = #{collegeId} AND semester = #{semester} AND status = #{status}")
    EvaluationRule findByCollegeAndSemesterAndStatus(@Param("collegeId") String collegeId, 
                                                     @Param("semester") String semester, 
                                                     @Param("status") String status);

    /**
     * 根据学院ID查询所有规则
     */
    @Select("SELECT * FROM t_evaluation_rule WHERE college_id = #{collegeId} ORDER BY create_time DESC")
    List<EvaluationRule> findByCollegeId(@Param("collegeId") String collegeId);

    /**
     * 查询所有启用的规则
     */
    @Select("SELECT * FROM t_evaluation_rule WHERE status = 'ENABLED' ORDER BY create_time DESC")
    List<EvaluationRule> findEnabledRules();
}
